﻿using System;
using System.Collections.Generic;
using System.Text;
using CFSystem.JXC.IDAL;
using CFSystem.JXC.Model;
using System.Data;
using System.Data.OleDb;
using DBUtility;


namespace CFSystem.JXC.AccessDAL
{
    public class Color1 : IColor
    {
        public Color1()
        { }

        /// <summary>
        /// Method to get all ColorInfo
        /// </summary>		
        /// <returns>Interface to Model Collection Generic of Colors</returns>
        public IList<ColorInfo> GetColors()
        {

            string sqlSelect = "SELECT * from tb_Color";

            OleDbDataReader dr = AccessHelper.ExecuteReader(AccessHelper.ConnectionString, CommandType.Text, sqlSelect);

            IList<ColorInfo> ColorItems = new List<ColorInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    ColorInfo bi = new ColorInfo(Convert.ToInt32(dr[0].ToString()), Convert.ToString(dr[1].ToString()));
                    ColorItems.Add(bi);
                }
                dr.Close();
            }
            return ColorItems;
        }

        /// <summary>
        /// Get information on a specific Color
        /// </summary>
        /// <param name="categoryId">Unique identifier for a Color</param>
        /// <returns>Business Entity representing an Color</returns>
        public ColorInfo GetColor(string ColorID)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ColorName"></param>
        public void InsertColor(string ColorName)
        {
            string sqlInsert = "insert into [tb_Color]([Color]) values('" + ColorName + "')";

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlInsert);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ColorID"></param>
        public void DelColorByID(int ColorID)
        {
            string sqlDel = "delete from [tb_Color] where [ColorID]=" + ColorID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlDel);

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ColorID"></param>
        /// <param name="updValue"></param>
        public void UpdateColorByID(int ColorID, string updValue)
        {
            string sqlUpd = "update [tb_Color] set [Color] ='" + updValue + "'" + " where [ColorID]=" + ColorID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlUpd);

        }
    }
}
